#include <51func.h>
int main(){
    const char query[] = "GET / HTTP/1.0\r\n"
        "Host:www.baidu.com\r\n"
        "\r\n";
    const char hostname[] = "www.baidu.com";
    // 首先根据域名获取ip地址
    struct hostent * pHost = gethostbyname(hostname);
    struct sockaddr_in addr;
    memcpy(&addr.sin_addr, pHost->h_addr_list[0],4);
    addr.sin_family = AF_INET;
    addr.sin_port = htons(80);

    int sockfd = socket(AF_INET,SOCK_STREAM,0);
    int ret = connect(sockfd,(struct sockaddr *)&addr,sizeof(addr));
    send(sockfd,query,strlen(query),0);

    char buf[40960] = {0};
    while(1){
        bzero(buf,sizeof(buf));
        ssize_t sret = recv(sockfd,buf,sizeof(buf),0);
        if(sret == 0){
            break;
        }
        printf("buf = %s\n", buf);
        printf("sret = %ld\n", sret);
    }
}
